package cn.stylefeng.guns.sys.modular.cleanRule.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.cleanRule.entity.CleanRule;
import cn.stylefeng.guns.sys.modular.cleanRule.model.params.CleanRuleParam;
import cn.stylefeng.guns.sys.modular.cleanRule.service.CleanRuleService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.kernel.model.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 数据清洗规则表控制器
 *
 * @author author
 * @Date 2020-11-16 15:33:41
 */
@Controller
@RequestMapping("/cleanRule")
public class CleanRuleController extends BaseController {

    private String PREFIX = "/modular/cleanRule/cleanRule";

    @Autowired
    private CleanRuleService cleanRuleService;

    /**
     * 跳转到主页面
     *
     * @author author
     * @Date 2020-11-16
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/cleanRule.html";
    }

    /**
     * 新增页面
     *
     * @author author
     * @Date 2020-11-16
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/cleanRule_add.html";
    }

    /**
     * 编辑页面
     *
     * @author author
     * @Date 2020-11-16
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/cleanRule_edit.html";
    }

    /**
     * 新增接口
     *
     * @author author
     * @Date 2020-11-16
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(CleanRuleParam cleanRuleParam) {
        this.cleanRuleService.add(cleanRuleParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author author
     * @Date 2020-11-16
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(CleanRuleParam cleanRuleParam) {
        this.cleanRuleService.update(cleanRuleParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author author
     * @Date 2020-11-16
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(CleanRuleParam cleanRuleParam) {
        this.cleanRuleService.delete(cleanRuleParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author author
     * @Date 2020-11-16
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(CleanRuleParam cleanRuleParam) {
        CleanRule detail = this.cleanRuleService.getById(cleanRuleParam.getDataCleanRuleId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author author
     * @Date 2020-11-16
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(CleanRuleParam cleanRuleParam) {
        return this.cleanRuleService.findPageBySpec(cleanRuleParam);
    }


    /**
     * 逻辑删除
     *
     * @param arr
     * @return
     */
    @ResponseBody
    @RequestMapping("/deleteCleanRule")
    public int deleteCleanRuleById(@RequestParam int[] arr) {
        int number = 0;
        for (int i = 0; i < arr.length; i++) {
            cleanRuleService.deleteCleanRuleInfo(arr[i]);
            number++;
        }
        return number;
    }

}


